<%@ page language="java" pageEncoding="UTF-8" isELIgnored="false"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="s" uri="http://www.springframework.org/tags" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN">
 
<html>
  <head>
    <link href="<s:url value="/resources"/>/css/style_new.css" rel="stylesheet" type="text/css" />
    <link href="<s:url value="/resources"/>/css/main_new.css" rel="stylesheet" type="text/css" />
    <link rel="stylesheet" type="text/css" media="screen" href="<s:url value="/resources"/>/css/cupertino/jquery-ui.min.css" />
    <link rel="stylesheet" type="text/css" media="screen" href="<s:url value="/resources"/>/css/ui.jqgrid.css" />
    <link rel="stylesheet" type="text/css" media="screen" href="<s:url value="/resources"/>/css/ui.multiselect.css" />
    <script type="text/javascript" src="<s:url value="/resources"/>/js/jquery-1.7.2.min.js"></script>
    <script type="text/javascript" src="<s:url value="/resources"/>/js/jquery-ui.custom.min.js"></script>  
    <script type="text/javascript" src="<s:url value="/resources"/>/js/i18n/grid.locale-cn.js"></script> 
    <script type="text/javascript" src="<s:url value="/resources"/>/js/jquery.jqGrid.min.js"></script>
    <script type="text/javascript" src="<s:url value="/resources"/>/js/i18n/jquery.ui.datepicker-zh-CN.js"></script>
    <style>
html, body {
	margin: 0;			 
	padding: 0;
    font-size: 85%;
}
</style>
    
  </head>
  
  <script type="text/javascript">  


    $(function(){      
    	
    $("#xinz").button(); 
    $("#chax").button();
    $("#shanc").button();
    $("#tib").button();
    $("#daoc").button();
    $("#fuz").button(); 
    $("#reset").button();
    $("#dialog-confirm").hide();
    $("#dialog-confirm1").hide();    
    $("#dialog-confirm2").hide();
    loadTab();
    $( "#datepicker" ).datepicker($.datepicker.regional[ "zh-CN" ]);
    $( "#datepicker1" ).datepicker($.datepicker.regional[ "zh-CN" ]); 
    $( "#zidqysj" ).datepicker($.datepicker.regional[ "zh-CN" ]); 
    $( "#zidqysj1" ).datepicker($.datepicker.regional[ "zh-CN" ]);       

    
 });
 
 function loadTab(){  
    //var sign = true;
    //if(i=='1' || i=='2'|| i=='3') sign = false;
    $("#myTab0").jqGrid({      
    //url:'findDsht?index='+i, 
    url:'findDsht', 
    datatype: 'json',
    mtype: 'post',         
   	colNames:['操作','合同号','企业合同号', '出卖人','发货单位名称', '买受人','收货单位','煤种','品种','价格','数量','合同总价','签订日期','合同状态','','hetid','toid','potraderid'],
   	colModel:[ 
   	    {name:'Verify',index:'id',width:120,align:"center",sortable:false},
   	    {name:'hetbh',index:'hetbh', width:120},	  		
   		{name:'hetlrbh',index:'hetlrbh', width:120},
   		{name:'chumdwmc',index:'chumdwmc', width:200},
   		{name:'fahdwmc',index:'fahdwmc', width:120},
   		{name:'maisdwmc',index:'maisdwmc', width:120 },
   		{name:'shouhdwmc',index:'shouhdwmc', width:120 },
   		{name:'meiz',index:'meiz', width:60 },	
   		{name:'pinz',index:'pinz', width:60 },	
   		{name:'jiag',index:'jiag', width:60 },
   		{name:'shul',index:'shul', width:60 },
   		{name:'htzj',index:'htzj', width:60 },
   		{name:'qianysj',index:'qianysj', width:80},	
   		{name:'htzt',index:'htzt', width:50},
   		{name:'zhuangt',index:'zhuangt', width:50, sortable:false},
   		{name:'hetid',index:'hetid'},
   		{name:'toid',index:'toid'},
   		{name:'potraderid',index:'potraderid'}
   	],
   
    jsonReader: {
           repeatitems : false, 
           id: 'hetid'
         },
    width: 1800, 
    shrinkToFit:true,    	
   	rowNum:10,
   	rowList:[10,20,30],     	
   	pager: '#pager0',   	
   	rownumbers: true,   	 
    viewrecords: true,
    multiselect: true,
    sortorder: 'desc',  
    //altRows:true,  
	caption: "煤炭交易合同",
	gridComplete:function()
	{ //在此事件中循环为每一行添加修改和删除链接 
		var ids=jQuery("#myTab0").jqGrid('getDataIDs'); 		
		for(var j=0; j<ids.length; j++)
		{ 
			var id=ids[j]; 	
			var jsv = $("#myTab0").jqGrid('getRowData',ids[j]);

			if(${orgid}==jsv.potraderid){
				if(jsv.zhuangt==0){
					  //保存 保存并提报
				    verify ="<a href='#' style='color:#f60' onclick='Verify("+ id +","+jsv.toid+")'>签订电子合同</a>";
				  }else if(jsv.zhuangt==1){
					  //撤销
					verify ="<a href='#' style='color:#f60' onclick='Verify("+ id +","+jsv.toid+")'>签订电子合同</a>";
				  }else if(jsv.zhuangt==6){
					//保存 保存并提报
				    verify ="<a href='#' style='color:#f60' onclick='Verify("+ id +","+jsv.toid+")'>签订电子合同</a>";
				  }else{
				    verify ="<a href='#' style='color:#f60' onclick='select("+ id +")'>查看</a>";
				  }		
			}else{
				if(jsv.zhuangt==0){
					  
					verify ="<a href='#' style='color:#f60' onclick='Dshtqr("+ id +")'>签订电子合同</a>";
				  }else if(jsv.zhuangt==1){
				    verify ="<a href='#' style='color:#f60' onclick='Dshtqr("+ id +")'>签订电子合同</a>";
				  }else if(jsv.zhuangt==6){
					verify ="<a href='#' style='color:#f60' onclick='Dshtqr("+ id +")'>签订电子合同</a>";
				  }else{
				    verify ="<a href='#' style='color:#f60' onclick='select("+ id +")'>查看</a>";
				  }		
			}
			  
			jQuery("#myTab0").jqGrid('setRowData',ids[j], { Verify: verify }); 
		} 
	} 	
  });
  $("#myTab0").jqGrid('setGridHeight','280px');
  $("#myTab0").jqGrid('hideCol',["chumdwmc"]);
  $("#myTab0").jqGrid('hideCol',["zhuangt"]);
  $("#myTab0").jqGrid('hideCol',["hetid"]);
  $("#myTab0").jqGrid('hideCol',["toid"]);
  $("#myTab0").jqGrid('hideCol',["potraderid"]);
  }

// 查询
function search(){ 
  var formdata = $("#form1").serialize();  
 $("#myTab0").jqGrid('setGridParam',{url:'findDsht?'+formdata,mtype:'post',page:1}).trigger("reloadGrid"); 
}

function openwindow(url){
	   var sheight = screen.height-120;
	    var swidth = screen.width-30;
	    var iTop = (window.screen.availHeight-30-sheight)/2;       //获得窗口的垂直位置;
	    var iLeft = (window.screen.availWidth-10-swidth)/2;           //获得窗口的水平位置;

	   var winoption ="height="+sheight+",width="+ swidth +",top="+iTop+",left="+iLeft+",toolbar=no,menubar=no,scrollbars=yes, resizable=yes,status=no";
	   //alert(winoption); 
	   var result=window.open("<s:url value="/"/>/htgl/"+url,"_blank",winoption);
}

function openqr(url){
    var sheight = screen.height-120;
    var swidth = screen.width-30;
    var iTop = (window.screen.availHeight-30-sheight)/2;       //获得窗口的垂直位置;
    var iLeft = (window.screen.availWidth-10-swidth)/2;           //获得窗口的水平位置;

   var winoption ="height="+sheight+",width="+ swidth +",top="+iTop+",left="+iLeft+",toolbar=no,menubar=no,scrollbars=yes, resizable=yes,status=no";
   //alert(winoption); 
   var result=window.open("<s:url value="/"/>/htgl/"+url,"_blank",winoption);

}

function reloadhtxx(){
   window.location.href="findDshtView";
}

function removeRow() {
	var s = $("#myTab0").jqGrid('getGridParam','selarrrow');
	if (s == "") {
        alert("请先选择报单，再点击删除！");
        return;
    }	
	var url = "<s:url value="/"/>/htgl/removeNdbd?htid="+s;
	$( "#dialog-confirm" ).dialog({
			resizable: false,
			height:140,
			modal: true,
			buttons: {
				"确认": function() {
					$.post(url, function(data) {
					var json =eval('(' + data + ')');
					if(json.result==1){
					   alert("删除成功！");
					   reloadhtxx();
					}else{
					   alert("删除失败！");
					}
                                                       
                   });                    
                   $( this ).dialog( "close" ); 
                   
				},
				"返回": function() {
					$( this ).dialog( "close" );
				}
			}
		});
}

function submitRow() {
	var s = $("#myTab0").jqGrid('getGridParam','selarrrow');
	if (s == "") {
        alert("请先选择报单，再点击提交！");
        return;
    }
    
	var url = "<s:url value="/"/>/htgl/submitDsht?htid="+s;
	$( "#dialog-confirm1" ).dialog({
			resizable: false,
			height:140,
			modal: true,
			buttons: {
				"确认": function() {
				    
					$.post(url, function(data) {					
                    var json =eval('(' + data + ')');
					   if(json.result==1){					   
					   alert("提交成功！");
					   reloadhtxx();
					   }else{					  
					   alert("提交失败！"+json.msg);
					   }   
                   });                  
                   $( this ).dialog( "close" );
				},
				"返回": function() {
					$( this ).dialog( "close" );
				}
			}
		});     
}


function copyRow(){
    var s = $("#myTab0").jqGrid('getGridParam','selarrrow');
    if (s == "") {
        alert("请先选择报单，再点击复制！");
        return;
    }
	var url = "<s:url value="/"/>/htgl/copyNdbd?htid="+s;
	$( "#dialog-confirm2" ).dialog({
			resizable: false,
			height:140,
			modal: true,
			buttons: {
				"确认": function() {
					$.post(url, function(data) {
					   var json =eval('(' + data + ')');
					   if(json.result==1){
					   alert("复制成功！");
					   reloadhtxx();
					   }else{
					   alert("复制失败！");
					   }
                   }); 
                   $( this ).dialog( "close" );                                       
				},
				"返回": function() {
					$( this ).dialog( "close" );
				}
			}
		});
}
function Verify(id,toid) { //单击修改链接的操作 
    var hetid= "";
   if(id.id!=undefined){
   hetid=id.id;
   }else{
   hetid=id;
   //var htbh = id.item(1).cells.item(14).innerHTML;	
   }
   openwindow('findDshtDetail?hetid='+hetid+'&toid='+toid );
}
function Dshtqr(id) { 
	   
	   
	  if(id.id!=undefined){
	  //openwindow('findDshtqrDetail?hetid='+id.id);
		 openqr('findDshtqrDetail?hetid='+id.id);
	  }else{
	  
		//openwindow('findDshtqrDetail?hetid='+id );
		  openqr('findDshtqrDetail?hetid='+id);
	  }
		
	 
}
function select(id) { 
    var hetid= "";
   if(id.id!=undefined){
   hetid=id.id;
   }else{
   hetid=id;
   //var htbh = id.item(1).cells.item(14).innerHTML;	
   }
   openwindow('findDsHtcxDetail?hetid='+hetid );         
 }
 
 function print(id){
   var hetid= "";
   if(id.id!=undefined){
   hetid=id.id;
   }else{
   hetid=id;	
   }
   window.open('findHtcxDetail?hetid='+hetid); 
 }
 
 function Canel(id) {  
   //alert(id.id); 
    var hetid=""; 
   if(id.id!=undefined){
      hetid=id.id;    
    }else{
    //hetid = id.item(1).cells.item(14).innerHTML;	
	  hetid=id;
    }   
    var url = "<s:url value="/"/>/htgl/cancelDsht?hetid="+hetid;
    $.post(url, function(data) {					
                    var json =eval('(' + data + ')');
					   if(json.result==1){					   
					   alert("撤销成功！");
					   reloadhtxx();
					   }else{					  
					   alert("撤销失败！"+json.msg);
					   }   
                   });                
 }

//重置
function resetSearch(){
	$('#list_search  input[type=text]').val('');
	$('#list_search select').val('-1');
}

function dc_excel(){ 
var a = 0;
if (qieye!="0") a= "1,2,3,4,5";
	form1.action="htgl/jytj_excel.action?jiaoylx=3&index="+a;
	form1.method = "post";
	form1.submit();
	}
	
	
	 ///excel
	function exportexcel(){ 
	  var formdata = $("#form1").serialize(); 
	  window.location.href("<s:url value="/htgl"/>/excelForRcbd?"+formdata+'&index='+qieye);
	}
	
</script>  
<body> 
<div class="container">  
<div class="containerbox">
<div class="btn-bar"> 
<p><img src="<s:url value="/resources"/>/img/htlc.gif" width="1200" height="40"></p>
</div>
<div class="btn-bar"> 
    
    <!--  <a href="#" class="btn" onclick="removeRow();"><img src="<s:url value="/resources"/>/img/ico_25.gif" /> <span>删除</span></a>
    
    <a href="#" class="btn" onclick="submitRow();"><img src="<s:url value="/resources"/>/img/operate_pass.gif" /> <span>提报</span></a> -->
    
    <a href="#" class="btn" onclick="copyRow();"><img src="<s:url value="/resources"/>/img/ico_25.png" /> <span>复制</span></a> 
    
    </div>
<div class="search mt10" id="list_search">
<form id="form1" method="post">

<table class="search-table" width="90%" cellpadding="0" cellspacing="0" border="0"> 
        <tr>
        	<td> 
            	合同编号: 
            </td>
            <td>
            	<input type="text" name="aa" class="form-textbox" style="width: 200px;"/> 
            </td>
            <td>
                煤种:
            </td>
            <td>
            	<div class="pr10 search-table-70"><div>
            	<select name="bb" class="form-textbox" style="width: 200px;">
            	<option value="-1" selected>==请选择==</option>
                   <c:forEach var="mz" items="${meiz}">
                   <option value="${mz.diccode}">
                   ${mz.dicname}
                   </option>
                   </c:forEach>
                 </select>
            	</div></div> 
            </td>            
            <td>
               品种 :
            </td>
            <td>
            	<div class="pr10 search-table-70"><div>
            	<select name="cc" class="form-textbox" style="width: 200px;">
            	<option value="-1" selected>==请选择==</option>
                   <c:forEach var="pz" items="${pinz}">
                   <option value="${pz.diccode}">
                   ${pz.dicname}
                   </option>
                   </c:forEach>
                 </select>
            	
            	</div></div>
            </td>
        </tr>
        <tr>
        <td>出卖人:</td>
        <td><input type="text" name="dd" class="form-textbox" style="width: 200px;"/></td>
        <td>发货单位:</td>
        <td><input type="text" name="ee" class="form-textbox" style="width: 200px;"/></td>
        <td>发站(局):</td>
        <td><input type="text" name="ff" class="form-textbox" style="width: 200px;"/></td>
        </tr>
        <tr>
        <td>买受人:</td>
        <td><input type="text"  name="gg" class="form-textbox" style="width: 200px;"/></td>
        <td>收货单位:</td>
        <td><input type="text" name="hh" class="form-textbox" style="width: 200px;"/></td>
        <td>到站(局):</td>
        <td><input type="text"  name="ii" class="form-textbox" style="width: 200px;"/></td>
        </tr>
        <tr>
        <td>价格:</td>
        <td><input type="text" name="jj" class="form-textbox" style="width: 93px;" onKeyUp="this.value=this.value.replace(/\D/g,'');" />
          --
          <input type="text" name="kk" class="form-textbox" style="width: 93px;" onKeyUp="this.value=this.value.replace(/\D/g,'');" /></td>
        <td>数量:</td>
        <td><input type="text" name="ll" class="form-textbox" style="width: 93px;" onKeyUp="this.value=this.value.replace(/\D/g,'');" />
          --
          <input type="text" name="mm" class="form-textbox" style="width: 93px;" onKeyUp="this.value=this.value.replace(/\D/g,'');" /></td>
        <td>签订日期:</td>
            <td>
            	<input id="datepicker" type="text" name="nn" class="form-textbox" style="width: 93px;"/> -- <input id="datepicker1" type="text" name="oo" class="form-textbox" style="width: 93px;"/>
            </td>
        </tr>
        <tr>
        <td>合同形式:</td>
        <td><div class="pr10 search-table-70"><div>
        <select name="pp" class="form-textbox" style="width: 200px;">
            <option value="-1" selected>==请选择==</option>
            <option value="3">省内</option>
            <option value="4">省外</option>
        </select>
        
        </div></div></td>
        <td>隶属行业:</td>
        <td><div class="pr10 search-table-70"><div>
            <select name="rr" class="form-textbox" style="width: 200px;">
                  <option value="-1" selected>==请选择==</option>
                   <c:forEach var="hy" items="${hangy}">
                   <option value="${hy.diccode}">
                   ${hy.dicname}
                   </option>
                   </c:forEach>
            </select>
        
        </div></div></td>
        <td>年度:</td>
        <td><div class="pr10 search-table-70"><div>
        <select name="uu" class="form-textbox" style="width: 200px;">
            <option value="-1" selected>==请选择==</option>
            <option value="2014">2014</option>
            <option value="2015">2015</option>
            <option value="2016">2016</option>
        </select>
        </div></div></td>
        </tr>
		<tr>
    <td align="left" valign="middle" colspan="6">
<table border="0" cellspacing="0" cellpadding="0" >
  <tr>
    <td align="right" class="pr10 search-table-70">&nbsp;</td>
    <td align="left"><input name="" type="button" class="form-button-query form-button" value="查询" onclick="search();"/>
    <input name="" type="button" class="form-button-reset form-button" value="重置"  onclick="resetSearch();"/></td>
  </tr>
</table></td>
  </tr>
  </table> 
  </form> 
  </div>  
       
   <div id="tabs">
			<!--<ul>
				<li><a href="#tabs-0">签订合同</a></li>
				<li><a href="#tabs-1">已提报</a></li>
				<li><a href="#tabs-2">已退回</a></li>
				<li><a href="#tabs-3">待确认</a></li>
			</ul>-->
			<div id="tabs-0">
				<table id="myTab0" class="scroll" cellpadding="0" cellspacing="0"></table>
				<div id="pager0" class="scroll"></div>
				<div id="message0" class="scroll"></div>
			</div>
			<!--  <div id="tabs-1">
				<table id="myTab1" class="scroll" cellpadding="0" cellspacing="0"></table>
				<div id="pager1" class="scroll"></div>
				<div id="message1" class="scroll"></div>
			</div>
			<div id="tabs-2">
				<table id="myTab2" class="scroll" cellpadding="0" cellspacing="0"></table>
				<div id="pager2" class="scroll"></div>
				<div id="message2" class="scroll"></div>
			</div>
			<div id="tabs-3">
				<table id="myTab3" class="scroll" cellpadding="0" cellspacing="0"></table>
				<div id="pager3" class="scroll"></div>
				<div id="message3" class="scroll"></div>
			</div>-->

   </div>
   <!--<div id="dialog-confirm"><strong>是否确认删除？</strong></div>
   <div id="dialog-confirm1"><strong>是否确认提报？</strong></div>-->
   <div id="dialog-confirm2"><strong>是否确认复制？</strong></div>
</div> 
</div>
</body>
</html>
